<template>
    <el-dialog :title="isEdit ? '修改' : '新增'" :visible.sync="dialogVisible" width="80%" :before-close="handleClose">
        <el-form :model="ruleForm" ref="ruleForm" label-width="100px">
            <el-row :gutter="20">
                <el-col :span="8">
                    <el-form-item label="传感器编号" prop="factoryNum">
                        <el-input v-model="ruleForm.factoryNum"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="温补系数" prop="tempCoefficient">
                        <el-input v-model="ruleForm.tempCoefficient"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="出厂波长1" prop="factoryWavelength_01">
                        <el-input v-model="ruleForm.factoryWavelength_01"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="20">
                <el-col :span="8">
                    <el-form-item label="传感器类型" prop="sensorStyle">
                        <el-select v-model="ruleForm.sensorStyle">
                            <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
                            </el-option>

                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="温补初值" prop="tempIntercept">
                        <el-input v-model="ruleForm.tempIntercept"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="出厂波长2" prop="factoryWavelength_02">
                        <el-input v-model="ruleForm.factoryWavelength_02"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="20">
                <el-col :span="8">
                    <el-form-item label="一次系数" prop="coefficient_01">
                        <el-input v-model="ruleForm.coefficient_01"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="物理通道" prop="physicalChannel">
                        <el-input v-model="ruleForm.physicalChannel"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="出厂波长3" prop="factoryWavelength_03">
                        <el-input v-model="ruleForm.factoryWavelength_03"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="20">
                <el-col :span="8">
                    <el-form-item label="二次系数" prop="coefficient_02">
                        <el-input v-model="ruleForm.coefficient_02"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="截距" prop="intercept">
                        <el-input v-model="ruleForm.intercept"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="出厂波长4" prop="factoryWavelength_04">
                        <el-input v-model="ruleForm.factoryWavelength_04"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button @click="dialogVisible = false">取 消</el-button>
            <el-button type="primary" :loading="loading" @click="save">确定</el-button>
        </span>
    </el-dialog>
</template>

<script>
import { Message } from 'element-ui'
import { dingbanchuanganqibiaoadd, dingbanchuanganqibiaoxiugai } from '../../../https/api/user'
const ruleForm = {
    factoryNum: '', // 传感器出厂编号
    tempCoefficient: '',
    factoryWavelength_01: '',
    sensorStyle: '',
    tempIntercept: '',
    factoryWavelength_02: '',
    coefficient_01: '',
    physicalChannel: '',
    factoryWavelength_03: '',
    coefficient_02: '',
    intercept: '',
    factoryWavelength_04: ''
}
export default {
    data() {
        return {
            dialogVisible: false,
            ruleForm,
            isEdit: false,
            loading: false,
            options: [
                { label: '顶板离层', value: '顶板离层' },
                { label: '锚杆应力', value: '锚杆应力' },
                { label: '钻孔应力', value: '钻孔应力' },
                { label: '光栅温度', value: '光栅温度' },
                { label: '锚索应力', value: '锚索应力' },
                { label: '恒阻锚索', value: '恒阻锚索' },
                { label: '顶底板位移', value: '顶底板位移' },
                { label: '单体位移', value: '单体位移' },
                { label: '单元支架', value: '单元支架' },
                { label: '多点位移', value: '多点位移' },
                { label: '可视化锚杆', value: '可视化锚杆' },
                { label: '应变传感器', value: '应变传感器' },
                { label: '可视化锚索', value: '可视化锚索' },
                
            ],
        };
    },
    methods: {
        show(data) {
            this.isEdit = !!data
            this.ruleForm = data || ruleForm
            this.dialogVisible = true
        },
        async save() {
            const api = this.isEdit ? dingbanchuanganqibiaoxiugai : dingbanchuanganqibiaoadd
            try {
                this.loading = true
                const result = await api(this.ruleForm)
                const message = this.isEdit ? '修改成功！' : '添加成功！'
                Message({
                    message,
                    type: 'success'
                })
                this.$parent.ChuanGanQiBiao()
                this.dialogVisible = false
                this.$refs.ruleForm.resetFields()
                // console.log('>>>>', result);
                // alert(result)
            } catch (e) {
                console.log(e)
            } finally {
                this.loading = false
            }
        },
        handleClose(done) {
            // this.$confirm('确认关闭？')
            // .then(_ => {
            done();
            // })
            // .catch(_ => { });
        }
    }
}
</script>

<style scoped lang="less">
.el-select {
    width: 100%;
}
</style>